<?php
namespace App\Api;

use PhalApi\Api;
use App\Domain\Login as LoginDomain;

/**
 * 登录注册模块接口服务
 */
class Login extends Api {
    public function getRules() {
        return array(
            'login' => array(
                'member_mobile' => array('name' => 'member_mobile', 'require' => true, 'desc' => '用户手机号'),
                'password' => array('name' => 'password', 'require' => true, 'min' => 6, 'max' => 20, 'desc' => '密码'),
            ),
            'register' => array(
                'member_mobile' => array('name' => 'member_mobile', 'require' => true, 'desc' => '用户手机号'),
                'password' => array('name' => 'password', 'require' => true, 'min' => 6, 'max' => 20, 'desc' => '密码'),
            ),
        );
    }
    /**
     * 登录接口
     * @desc 根据账号和密码进行登录操作
     * @return int user_id 用户ID
     * @return string member_mobile 用户绑定的手机号
     * @return string member_name 用户姓名
     * @return url member_avatar 用户头像
     * @return string address 收货地址
     * @return string member_birthday 生日
     * @return int member_sex 性别 1男 2女
     * @return string token 登录token
     */
    public function login() {
        $domain = new LoginDomain();
        return $domain->login($this->member_mobile, $this->password);
    }
    /**
     * 注册接口
     * @desc 注册接口
     * @return int user_id 用户ID
     */
    public function register() {
        $domain = new LoginDomain();
        //列出所有需要添加的参数
        $insertData = array();
        $insertData['member_mobile'] = $this->member_mobile;
        $insertData['password'] = $this->password;
        return $domain->register($insertData);
    }
} 
